<%@ page contentType="text/html; charset=utf-8" %>
<%@taglib prefix="s" uri="/struts-tags" %>

<html>
<head>
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/admin.css" type="text/css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/themes/default/easyui.css">  
<script language="javascript" src="${pageContext.request.contextPath}/js/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/easyui-lang-zh_CN.js"></script>
<script language="javascript" src="${pageContext.request.contextPath}/js/datacheck.js"></script>
<script LANGUAGE="JavaScript">
var q = jQuery.noConflict();
function findModuleByModuleId(){
	var $parId = jQuery.trim(jQuery('#parentId').val());
	if($parId!=""){
		jQuery.getJSON(
			'${pageContext.request.contextPath}/findModuleByModuleId.do',{iModuleid:$parId},function(json){
				jQuery('#parentName').val(json.json.smodulename);
		});

	}
}
function findMaxIorder(){
	var $parId = jQuery.trim(jQuery('#parentId').val());
	if($parId!=""){
		jQuery.getJSON(
			'${pageContext.request.contextPath}/findMaxIorder.do',{iModuleid:$parId},function(json){
				jQuery('#iorder').val(json.json);
		});
	}
}
//验证栏目是否已经存在
function validModuleName(){
	var $moduleName = jQuery.trim(jQuery('#moduleName').val());
	var $imoduleid = jQuery.trim(jQuery('#imoduleid').val());
	var exist = true;
	if($moduleName == ""){
		alert('请填写栏目名称');
		return false;
	}
	
	jQuery.ajax({
		url:'${pageContext.request.contextPath}/back/validModuleName.html',
		type:'post',
		data:{'obj.smodulename':$moduleName,'obj.imoduleid':$imoduleid},
		async:false,
		success:function(json){
			if(json.isNameExist){
				alert('栏目已存在');
				exist = false;
			}
		}
	});
	if(!exist){
		return false;
	}else{
		q.ajax({
			url:'${pageContext.request.contextPath}/back/saveModule.html',
			type:'post',
			data:{'obj.smodulename':q('#moduleName').val(),
				'obj.iorder':q('#iorder').val(),
				'obj.imoduleid':q('#imoduleid').val(),
				'obj.moduleType':q('#moduleType').val()},
			async:false,
			success:function(json){
				if(json.successful){
					alert('保存成功!');
					window.location.href='${pageContext.request.contextPath}/back/moduleLst.html';
				}
			},
			error:function(){
				alert('网络出现异常，请稍后重试!');
			}
		});
	}
}
jQuery(function(){
	findModuleByModuleId();
	findMaxIorder();
});



</script>
<title>增加栏目</title>
</head>

<body>
<div>
<table border=0 width="90%" cellspacing="0" cellpadding="0" align="center">
<tr height=28>
<td><u>新闻栏目</u></td>
</tr>
<tr height=10>
<td></td>
</tr>
</table>
<form name="frm1" method="post" action="" >
<s:hidden name="obj.imoduleid" id="imoduleid"/>
<s:hidden name="obj.moduleType" id="moduleType"/>
  <table border=0 width="90%" align="center" cellspacing="1" cellpadding="1" bgcolor="#336699">
    <tr bgcolor="#FFFFFF" height=28>
      <td width="301">
        <div align="right">栏目名称：</div>
      </td>
      <td width="483">
        <s:textfield name="obj.smodulename" size="30" id="moduleName" maxlength="50"  />
      </td>
    </tr>
    <tr bgcolor="#FFFFFF" height=28>
      <td width="301">
        <div align="right">级&nbsp;&nbsp;&nbsp;&nbsp;别：</div>
      </td>
      <td width="483">
        <s:textfield type="text" name="obj.iorder" size="30" id="iorder" maxlength="8" />
      </td>
    </tr>
  </table><br>
<p align="center">
<a href="###" onclick="validModuleName()" class="easyui-linkbutton" >确定</a>&nbsp;&nbsp;
<a href="javascript:history.back()" onclick="" class="easyui-linkbutton" >返回</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</p>
</form>
</div>
</body>

</html>
